/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author Pierro
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@NamedQueries({
    @NamedQuery(name = "CompteCourant.findAll", query = "SELECT c FROM CompteCourant c ORDER BY c.id ASC"),
    @NamedQuery(name = "CompteCourant.count", query = "SELECT count(c) FROM CompteCourant c"),
    @NamedQuery(name = "CompteCourant.findById", query = "SELECT c FROM CompteCourant c WHERE c.id = :id ORDER BY c.id DESC"),
    @NamedQuery(name = "CompteCourant.findByNomSolde", query = "SELECT c FROM CompteCourant c WHERE c.soldeCompte = :soldeCompte")})
public class CompteCourant extends CompteBanquaire implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private int nbrOperation;
    private String type;
    
    // 1 compte courant est associe a 1 seul client
    //@OneToOne(cascade=CascadeType.ALL)
   
    //@OneToOne(cascade = {CascadeType.ALL, CascadeType.REMOVE})
    //private Client client;

    
    
    
    /// un compteCourant a plusiers operations bancaires
    // relation 1 a plusieurs
    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private Collection<OperationBancaire> operations = new ArrayList();

    

    public CompteCourant() {
        super();
    }

    public CompteCourant( double soldeCompte) {
        super(soldeCompte);
        this.type = "CptCourant";
        this.nbrOperation = this.operations.size();
    }
    
    
    /**
    public CompteCourant( double soldeCompte, Client client) {
        super(soldeCompte);
        this.type = "CptCourant";
        this.nbrOperation = this.operations.size();
        this.client = client;
    }
    
    **/
    
    
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }
    
    
    
    
    

    public Collection<OperationBancaire> getOperations() {
        this.nbrOperation = nbrOperation +1;
        return operations;
    }

    public void setOperations(Collection<OperationBancaire> operations) {
        this.operations = operations;
    }
    
    
    
    
    
    public int getNbrOperation() {
        return nbrOperation;
    }

    public void setNbrOperation(int nbrOperation) {
        this.nbrOperation = nbrOperation;
    }
    
    
    
    
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CompteCourant)) {
            return false;
        }
        CompteCourant other = (CompteCourant) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.CompteCourant[ id=" + id + " ]";
    }
}
